/// 群聊信息模型
class GroupChatModel {
  final String groupId; // 群聊ID
  final String groupName; // 群聊名称
  final String groupDescription; // 群聊描述
  final String groupCoverImage; // 群聊封面图
  final String location; // 地点
  final String creatorId; // 创建者ID
  final List<String> memberIds; // 成员ID列表
  final DateTime createTime; // 创建时间

  const GroupChatModel({
    required this.groupId,
    required this.groupName,
    required this.groupDescription,
    required this.groupCoverImage,
    required this.location,
    required this.creatorId,
    required this.memberIds,
    required this.createTime,
  });

  /// 复制并修改群聊信息
  GroupChatModel copyWith({
    String? groupId,
    String? groupName,
    String? groupDescription,
    String? groupCoverImage,
    String? location,
    String? creatorId,
    List<String>? memberIds,
    DateTime? createTime,
  }) {
    return GroupChatModel(
      groupId: groupId ?? this.groupId,
      groupName: groupName ?? this.groupName,
      groupDescription: groupDescription ?? this.groupDescription,
      groupCoverImage: groupCoverImage ?? this.groupCoverImage,
      location: location ?? this.location,
      creatorId: creatorId ?? this.creatorId,
      memberIds: memberIds ?? this.memberIds,
      createTime: createTime ?? this.createTime,
    );
  }

  /// 从JSON创建群聊对象
  factory GroupChatModel.fromJson(Map<String, dynamic> json) {
    return GroupChatModel(
      groupId: json['groupId'] as String,
      groupName: json['groupName'] as String,
      groupDescription: json['groupDescription'] as String,
      groupCoverImage: json['groupCoverImage'] as String,
      location: json['location'] as String,
      creatorId: json['creatorId'] as String,
      memberIds: List<String>.from(json['memberIds'] as List),
      createTime: DateTime.parse(json['createTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'groupId': groupId,
      'groupName': groupName,
      'groupDescription': groupDescription,
      'groupCoverImage': groupCoverImage,
      'location': location,
      'creatorId': creatorId,
      'memberIds': memberIds,
      'createTime': createTime.toIso8601String(),
    };
  }

  @override
  String toString() {
    return 'GroupChatModel(groupId: $groupId, groupName: $groupName, groupDescription: $groupDescription, groupCoverImage: $groupCoverImage, location: $location, creatorId: $creatorId, memberIds: $memberIds, createTime: $createTime)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is GroupChatModel &&
        other.groupId == groupId &&
        other.groupName == groupName &&
        other.groupDescription == groupDescription &&
        other.groupCoverImage == groupCoverImage &&
        other.location == location &&
        other.creatorId == creatorId &&
        other.memberIds == memberIds &&
        other.createTime == createTime;
  }

  @override
  int get hashCode {
    return groupId.hashCode ^
        groupName.hashCode ^
        groupDescription.hashCode ^
        groupCoverImage.hashCode ^
        location.hashCode ^
        creatorId.hashCode ^
        memberIds.hashCode ^
        createTime.hashCode;
  }
}

/// 群聊消息模型
class GroupMessageModel {
  final String messageId; // 消息ID
  final String groupId; // 群聊ID
  final String senderId; // 发送者ID
  final String content; // 消息内容
  final DateTime sendTime; // 发送时间

  const GroupMessageModel({
    required this.messageId,
    required this.groupId,
    required this.senderId,
    required this.content,
    required this.sendTime,
  });

  /// 复制并修改消息
  GroupMessageModel copyWith({
    String? messageId,
    String? groupId,
    String? senderId,
    String? content,
    DateTime? sendTime,
  }) {
    return GroupMessageModel(
      messageId: messageId ?? this.messageId,
      groupId: groupId ?? this.groupId,
      senderId: senderId ?? this.senderId,
      content: content ?? this.content,
      sendTime: sendTime ?? this.sendTime,
    );
  }

  /// 从JSON创建消息对象
  factory GroupMessageModel.fromJson(Map<String, dynamic> json) {
    return GroupMessageModel(
      messageId: json['messageId'] as String,
      groupId: json['groupId'] as String,
      senderId: json['senderId'] as String,
      content: json['content'] as String,
      sendTime: DateTime.parse(json['sendTime'] as String),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'messageId': messageId,
      'groupId': groupId,
      'senderId': senderId,
      'content': content,
      'sendTime': sendTime.toIso8601String(),
    };
  }

  @override
  String toString() {
    return 'GroupMessageModel(messageId: $messageId, groupId: $groupId, senderId: $senderId, content: $content, sendTime: $sendTime)';
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;
    return other is GroupMessageModel &&
        other.messageId == messageId &&
        other.groupId == groupId &&
        other.senderId == senderId &&
        other.content == content &&
        other.sendTime == sendTime;
  }

  @override
  int get hashCode {
    return messageId.hashCode ^
        groupId.hashCode ^
        senderId.hashCode ^
        content.hashCode ^
        sendTime.hashCode;
  }
}
